package org.huangrui.redis.controller;

import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author hr
 * @Create 2024-05-17 09:10
 */
@Slf4j
@RestController
@Tag(name = "分布式锁")
public class RedLockController {
    /*public static final String CACHE_KEY_REDLOCK = "REDLOCK";
    @Autowired RedissonClient redissonClient1;
    @Autowired RedissonClient redissonClient2;
    @Autowired RedissonClient redissonClient3;

    @GetMapping(value = "/multilock")
    @Operation(summary = "分布式多重锁")
    public String getMultiLock(){
        String taskThreadID = Thread.currentThread().getId()+"";
        RLock lock1 = redissonClient1.getLock(CACHE_KEY_REDLOCK);
        RLock lock2 = redissonClient2.getLock(CACHE_KEY_REDLOCK);
        RLock lock3 = redissonClient3.getLock(CACHE_KEY_REDLOCK);
        RedissonMultiLock redLock = new RedissonMultiLock(lock1, lock2, lock3);
        redLock.lock();
        try{
            log.info("come in biz multilock:{}",taskThreadID);
            try { TimeUnit.SECONDS.sleep(60); } catch (InterruptedException e) { e.printStackTrace(); }
            log.info("task is over multilock:{}",taskThreadID);
        }catch (Exception e){
            e.printStackTrace();
            log.error("multilock exception:{}",e.getCause()+"\t"+e.getMessage());
        }finally {
            redLock.unlock();
            log.info("释放分布式锁成功key:{}",CACHE_KEY_REDLOCK);
        }
        return "multilock task is over: "+taskThreadID;
    }*/
}
